﻿/*
    This file is part of News Worm.

    News Worm is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    News Worm is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with News Worm.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using Microsoft.Win32;
using System.Security.Cryptography;
using System.IO;

namespace NewsWorm {
    internal class RegistryManager {
        internal RegistryManager( string path ) {
            m_NewsWormKey = Registry.CurrentUser;
            m_NewsWormKey = m_NewsWormKey.CreateSubKey( "Software\\NewsWorm",
                RegistryKeyPermissionCheck.ReadWriteSubTree );
            m_Path = path;
        }

        ~RegistryManager() {
            m_NewsWormKey.Close();
        }

        private RegistryKey m_NewsWormKey;
        private string m_Path;

        internal bool IsFirstRun {
            get {
                return Convert.ToBoolean( m_NewsWormKey.GetValue( "FirstRun", 1 ) );
            }
        }

        internal void DisableFirstRun() {
            m_NewsWormKey.SetValue( "FirstRun", false, RegistryValueKind.DWord );
        }

        internal bool ShowRecommendedFeedsOnStartUp {
            get {
                return Convert.ToBoolean( m_NewsWormKey.GetValue( "ShowRecommendedFeedsOnStartUp", 1 ) );
            }
        }

        internal bool ShowRemoveFeedConfirmation {
            get {
                return Convert.ToBoolean( m_NewsWormKey.GetValue( "DontShowRemoveFeedConfirm", 1 ) );
            }
        }

        internal void SetShowRecommendedFeedsOnStartUp( bool value ) {
            m_NewsWormKey.SetValue( "ShowRecommendedFeedsOnStartUp", value, RegistryValueKind.DWord );
        }

        internal void SetShowRemoveFeedConfirm( bool value ) {
            m_NewsWormKey.SetValue( "DontShowRemoveFeedConfirm", value, RegistryValueKind.DWord );
        }
    }
}
